package com.ziyun.erp.web.modules.order.controller;

import com.ziyun.erp.modules.order.entity.UserPaymentEntity;
import com.ziyun.erp.modules.order.service.UserPaymentService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 用户支付记录表
 *
 * @author guizhao
 * @email ...
 * @date 2018-08-06 11:45:03
 */
@RestController
@RequestMapping("order/userpayment")
public class UserPaymentController {
    @Autowired
    private UserPaymentService userPaymentService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("order:userpayment:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userPaymentService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{paymentId}")
    @RequiresPermissions("order:userpayment:info")
    public R info(@PathVariable("paymentId") String paymentId){
        UserPaymentEntity userPayment = userPaymentService.selectById(paymentId);

        return R.ok().put("userPayment", userPayment);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("order:userpayment:save")
    public R save(@RequestBody UserPaymentEntity userPayment){
        userPaymentService.insert(userPayment);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("order:userpayment:update")
    public R update(@RequestBody UserPaymentEntity userPayment){
        ValidatorUtils.validateEntity(userPayment);
        userPaymentService.updateAllColumnById(userPayment);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("order:userpayment:delete")
    public R delete(@RequestBody String[] paymentIds){
        userPaymentService.deleteBatchIds(Arrays.asList(paymentIds));

        return R.ok();
    }

}
